package cn.jly.spring.annotation.ioc.bean;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author lanyangji
 * @description 测试bean的后置处理器
 * @date 2020/11/12 下午 5:40
 */
@Component
@Data
@NoArgsConstructor
@AllArgsConstructor
public class MyBean implements BeanPostProcessor {
    private String name;

    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("MyBean.postProcessBeforeInitialization");
        System.out.println("---> bean = " + bean);
        System.out.println("---> beanName = " + beanName);
        this.name = beanName;
        return bean;
    }

    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("MyBean.postProcessAfterInitialization");
        return bean;
    }
}
